package org.springframework.security.samples.other;

import org.apache.commons.lang.StringUtils;

import java.text.SimpleDateFormat;
import java.util.Date;

public class TimeUtil {

    public static String formatMilliseconds(long milliseconds, String format) {
        if (StringUtils.isBlank(format)) {
            format = "yyyy-MM-dd HH:mm:ss SSS";
        }
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        Date resultdate = new Date(milliseconds);
        return sdf.format(resultdate);
    }

    public static String formatMilliseconds(long milliseconds) {
        return formatMilliseconds(milliseconds, null);
    }
}
